import db from "../../db";

export default defineEventHandler(async (event) => {
  const { s_id } = await getQuery(event);
  if (!Number(s_id)) {
    return {
      code: -1,
      msg: "参数错误: s_id",
    };
  }
  try {
    const [rows] = await db.query(`SELECT case_id,title,cover,content,create_time,update_time FROM customer_case WHERE case_id=?`, [s_id]);
    const res = (rows as any)[0]; // 转换为对象
    return {
      code: 1,
      messsage: "查询成功",
      data: res || null,
    };
  } catch (error) {
    console.error(error);
    return {
      code: 500,
      messsage: "服务器错误",
    };
  }
});
